﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.TMS.VehicleBusinessMapping;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.TMS.VehicleBusinessMapping;

namespace BCTMSRESTful.Controllers.Management.TMS.VehicleBusinessMapping
{
    /// <summary>
    /// 车辆与业务配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class VehicleBusinessMappingController : ManagementBaseController
    {
        private readonly IVehicleBusinessMappingService vehicleBusinessMappingService;

        public VehicleBusinessMappingController(IVehicleBusinessMappingService vehicleBusinessMappingService)
        {
            this.vehicleBusinessMappingService = vehicleBusinessMappingService;
        }

        #region 添加车辆与业务配置
        /// <summary>
        ///  添加车辆与业务配置
        /// </summary>
        /// <param name="requestDto">车辆与业务配置信息</param>
        /// <response code="201">添加车辆与业务配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加车辆与业务配置")]
        [ProducesResponseType(typeof(VehicleBusinessMappingDto), 201)]
        public IActionResult Post(
            [FromBody] VehicleBusinessMappingRequestDto requestDto)
        {
            var result = this.vehicleBusinessMappingService.Add(this.Admin,requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改车辆与业务配置
        /// <summary>
        ///  修改车辆与业务配置
        /// </summary>
        /// <param name="vehicleBusinessMappingId">车辆与业务配置Id</param>
        /// <param name="requestDto">车辆与业务配置信息</param>
        /// <response code="200">修改车辆与业务配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{vehicle_business_mapping_id}")]
        [Log("修改车辆与业务配置")]
        [ProducesResponseType(typeof(VehicleBusinessMappingDto), 200)]
        public IActionResult Put([FromRoute(Name = "vehicle_business_mapping_id")]int vehicleBusinessMappingId,[FromBody] VehicleBusinessMappingRequestDto requestDto)
        {
            var putDto = requestDto.As<VehicleBusinessMappingPutDto>();
            putDto.VehicleBusinessMappingId = vehicleBusinessMappingId;
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingService.Update(this.Admin,putDto));
        }
        #endregion

        //#region 修改车辆与业务配置(重写)
        ///// <summary>
        /////  修改车辆与业务配置(重写)
        ///// </summary>
        ///// <param name="putDto">车辆与业务配置信息</param>
        ///// <response code="200">修改车辆与业务配置成功</response>
        ///// <response code="400">请求参数或输入的数据不正确。</response>
        ///// <response code="500">服务器发生错误。</response>
        ///// <response code="501">某些功能尚未实现。</response>
        ///// <returns></returns>
        //[HttpPut("[action]/{vehicle_business_mapping_id}")]
        //[Log("修改车辆与业务配置")]
        //[ProducesResponseType(typeof(VehicleBusinessMappingDto), 200)]
        //public IActionResult Overwrite([FromBody] VehicleBusinessMappingOverwriteDto putDto)
        //{
        //    return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingService.Update(this.Admin, putDto));
        //}
        //#endregion

        #region 删除车辆与业务配置
        /// <summary>
        ///  删除车辆与业务配置
        /// </summary>
        /// <param name="vehicleBusinessMappingId">车辆与业务配置Id</param>
        /// <response code="204">删除车辆与业务配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{vehicle_business_mapping_id}")]
        [Log("删除车辆与业务配置")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "vehicle_business_mapping_id")] int vehicleBusinessMappingId)
        {
            this.vehicleBusinessMappingService.Delete(this.Admin,vehicleBusinessMappingId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取车辆与业务配置
        /// <summary>
        ///  获取车辆与业务配置
        /// </summary>
        /// <param name="vehicleBusinessMappingId">车辆与业务配置Id</param>
        /// <response code="200">获取车辆与业务配置</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{vehicle_business_mapping_id}")]
        [ProducesResponseType(typeof(VehicleBusinessMappingDto), 200)]
        public IActionResult Get([FromRoute(Name = "vehicle_business_mapping_id")] int vehicleBusinessMappingId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingService.Get(vehicleBusinessMappingId));
        }
        #endregion

        #region 获取车辆与业务配置列表
        /// <summary>
        ///  获取车辆与业务配置列表
        /// </summary>
        /// <response code="200">获取车辆与业务配置列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{county_code}")]
        [ProducesResponseType(typeof(IEnumerable<VehicleBusinessMappingDto>), 200)]
        public IActionResult List([FromRoute(Name = "county_code")]string countyCode)
        {
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingService.GetList());
        }
        #endregion

        #region 获取车辆与业务配置（分页）
        /// <summary>
        ///  获取车辆与业务配置（分页）
        /// </summary>
        /// <param name="vehicleTypeId">车型Id</param>
        /// <param name="vehicleTransportBusinessConfigId">车辆运输业务配置Id</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取车辆与业务配置（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<VehicleBusinessMappingDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "vehcile_type_id")] int? vehicleTypeId,
            [FromQuery(Name = "vehicle_transport_business_config_id")] int? vehicleTransportBusinessConfigId,
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingService.Query(vehicleTransportBusinessConfigId,vehicleTypeId, enabled, start, end, sortName, ascending, index, size));
        }
        #endregion

        #region 启用/禁用车辆与业务配置
        /// <summary>
        ///  启用/禁用车辆与业务配置
        /// </summary>
        /// <param name="vehicleBusinessMappingId">车辆与业务配置Id</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="vehicleBusinessMappingOverwriteId">车辆与业务配置重写Id</param>
        /// <param name="countyCode">区县编码</param>
        /// <response code="204">启用/禁用车辆与业务配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("[action]/{vehicle_business_mapping_id}/{enabled}")]
        [Log("启用/禁用车辆与业务配置")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "vehicle_business_mapping_id")] int vehicleBusinessMappingId,
            [FromRoute(Name = "enabled")] bool enabled,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "vehicle_business_mapping_overwrite_id")] int? vehicleBusinessMappingOverwriteId)
        {
            if (enabled)
            {
                this.vehicleBusinessMappingService.Enabled(this.Admin,vehicleBusinessMappingId, vehicleBusinessMappingOverwriteId, countyCode);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            else
            {
                this.vehicleBusinessMappingService.Disabled(this.Admin,vehicleBusinessMappingId, vehicleBusinessMappingOverwriteId, countyCode);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
        }
        #endregion
    }
}

